package edu.lnu.ums.ui;

import edu.lnu.ums.service.IDictionaryService;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.model.SelectItem;

public class DictionariesBean {  
    @EJB(mappedName="UMS/DictionaryService/local")
    private IDictionaryService dictionaryService;

    private TreeBean treeBean;

    public List<SelectItem> getTypes() {
        return transformCollection(dictionaryService.getTypes(treeBean.getSelectedObject()));
    }
    
    public List<SelectItem> getSexes() {
        return transformCollection(dictionaryService.getSexes(treeBean.getSelectedObject()));
    }

       public List<SelectItem> getMonths() {
        return transformCollection(dictionaryService.getMonths(treeBean.getSelectedObject()));
    }
    
    public List<SelectItem> getCountries() {
        return transformCollection(dictionaryService.getCountries(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getSubjects() {
        return transformCollection(dictionaryService.getSubjects(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getWorkers() {
        return transformCollection(dictionaryService.getWorkers(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getStudents() {
        return transformCollection(dictionaryService.getStudents(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getTeachers() {
        return transformCollection(dictionaryService.getTeachers(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getFaculties() {
        return transformCollection(dictionaryService.getFaculties(treeBean.getSelectedObject()));
    }

    public List<SelectItem> getHumans() {
        return transformCollection(dictionaryService.getHumans(treeBean.getSelectedObject()));
    }

    public TreeBean getTreeBean() {
        return treeBean;
    }

    public void setTreeBean(TreeBean treeBean) {
        this.treeBean = treeBean;
    }
    
    private List<SelectItem> transformCollection(List<?> list) {
        List<SelectItem> items = new ArrayList<SelectItem>();
        
        for (Object obj : list) {
            items.add(new SelectItem(obj));       
        }
        
        return items;
    }    
}
